package com.ymatou.iapi.dguser.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.CreateUserBackBean;
import com.ymatou.iapi.dguser.parameter.GetByMobileAndPwdBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.GetByMobileAndPwdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
/**
*根据手机号和密码获取用户信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetByMobileAndPwd{
	private static GetByMobileAndPwdBean getbymobileandpwdBean;
	private static GetByMobileAndPwdCall getbymobileandpwdCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据手机号和密码获取用户信息");
	}

	@Before
	public void caseUp() {
		getbymobileandpwdBean=new GetByMobileAndPwdBean();
		getbymobileandpwdCall=new GetByMobileAndPwdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getbymobileandpwdCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetByMobileAndPwd_001() {
		Logger.start(true,"手机号与密码正确，成功");
		try {
			UserCreateBean iu = DGUserCallService.initSellerUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(iu);
			getbymobileandpwdBean.setMobile(iu.getMobile());
			getbymobileandpwdBean.setPassword(iu.getLoginPwd());
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();			
			Logger.verifyEquals("true", getbymobileandpwdCall.getString("success"), "验证success");
			Logger.verifyEquals(userId,getbymobileandpwdCall.getJsonObject().get("userDto").getAsJsonObject().get("userId").getAsInt(),"验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetByMobileAndPwd_002() {
		Logger.start(true,"密码错误，失败");
		try {
			UserCreateBean iu = DGUserCallService.initSellerUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(iu);
			getbymobileandpwdBean.setMobile(iu.getMobile());
			getbymobileandpwdBean.setPassword(iu.getLoginPwd()+"1");
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();			
			Logger.verifyEquals("true", getbymobileandpwdCall.getString("success"), "验证success");
			Logger.verifyEquals(false,getbymobileandpwdCall.getJsonObject().has("userDto"),"验证userDto");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetByMobileAndPwd_003() {
		Logger.start(true,"手机号不存在，失败");
		try {
			UserCreateBean iu = DGUserCallService.initSellerUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(iu);
			getbymobileandpwdBean.setMobile("11111111111");
			getbymobileandpwdBean.setPassword(iu.getLoginPwd());
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();			
			Logger.verifyEquals("true", getbymobileandpwdCall.getString("success"), "验证success");
			
			Logger.verifyEquals(false,getbymobileandpwdCall.getJsonObject().has("userDto"),"验证userDto");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetByMobileAndPwd_004() {
		Logger.start(true,"手机号为空，失败");
		try {
			UserCreateBean iu = DGUserCallService.initSellerUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(iu);
//			getbymobileandpwdBean.setMobile("");
			getbymobileandpwdBean.setPassword(iu.getLoginPwd());
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();			
			Logger.verifyEquals("false", getbymobileandpwdCall.getString("success"), "验证success");
			Logger.verifyEquals(false,getbymobileandpwdCall.getJsonObject().has("userDto"),"验证userDto");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetByMobileAndPwd_005() {
		Logger.start(true,"密码为空，失败");
		try {
			UserCreateBean iu = DGUserCallService.initSellerUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(iu);
			getbymobileandpwdBean.setMobile(iu.getMobile());
//			getbymobileandpwdBean.setPassword(iu.getLoginPwd());
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();			
			Logger.verifyEquals("false", getbymobileandpwdCall.getString("success"), "验证success");
			Logger.verifyEquals(false,getbymobileandpwdCall.getJsonObject().has("userDto"),"验证userDto");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetByMobileAndPwd_006() {
		Logger.start(true,"两个手机号相同，密码不同，正确查出两个账号");
		try {
			UserCreateBean iu1 = DGUserCallService.initSellerUsercreateBean();
			iu1.setMobileAreaCode("86");
			iu1.setLoginPwd("123456");
			int userId1=DGUserCallService.UserCreateCall(iu1);
			UserCreateBean iu2 = DGUserCallService.initSellerUsercreateBean();
			iu2.setMobileAreaCode("80");
			iu2.setMobile(iu1.getMobile());
			iu2.setLoginPwd("456789");
			int userId2=DGUserCallService.UserCreateCall(iu2);
			getbymobileandpwdBean.setMobile(iu1.getMobile());
			getbymobileandpwdBean.setPassword(iu1.getLoginPwd());
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();
			Logger.verifyEquals("true", getbymobileandpwdCall.getString("success"), "验证success");
			Logger.verifyEquals(userId1,getbymobileandpwdCall.getJsonObject().get("userDto").getAsJsonObject().get("userId").getAsInt(),"验证用户1的userid");
			
			getbymobileandpwdBean.setMobile(iu2.getMobile());
			getbymobileandpwdBean.setPassword(iu2.getLoginPwd());
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();
			Logger.verifyEquals("true", getbymobileandpwdCall.getString("success"), "验证success");
			Logger.verifyEquals(userId2,getbymobileandpwdCall.getJsonObject().get("userDto").getAsJsonObject().get("userId").getAsInt(),"验证用户2的userid");
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@Ignore
	@TestCase
	public void Tc_GetByMobileAndPwd_007() {
		Logger.start(true,"两个手机号相同，密码相同，检查返回结果（忽略）");
		try {
			getbymobileandpwdBean.setMobile("13608500000");//重复数据
			getbymobileandpwdBean.setPassword("yyt123456");
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();			
			Logger.verifyEquals("true", getbymobileandpwdCall.getString("success"), "验证success");
			/**结果 ：两个手机号相同会查询出最后一个数据*/
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetByMobileAndPwd_008() {
		Logger.start(true,"独立商家账户，登录公版小程序，失败");
		try {
			CreateUserBackBean u = DGUserCallService.initUsercreateNewBean();
			u.setUserType(1);
			Integer user = DGUserCallService.UserCreateNewCall(u);
			DGUserCallService.ReceiveUserCreateNewCall(user);
			
			
			getbymobileandpwdBean.setMobile(u.getMobile());//重复数据
			getbymobileandpwdBean.setPassword(u.getLoginPwd());
			getbymobileandpwdCall.setData(getbymobileandpwdBean);
			getbymobileandpwdCall.callService();			
			Logger.verifyEquals("true", getbymobileandpwdCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}